package com.crm.redis.service.cluePoolManager.impl;

import com.crm.model.entity.cluePoolManager.CluePoolPrivate;
import com.crm.model.entity.cluePoolManager.CluePoolPublic;
import com.crm.redis.RedisPrefix;
import com.crm.redis.mapper.ValueRMapper;
import com.crm.redis.service.cluePoolManager.CluePoolPrivateRedisService;
import com.crm.redis.service.cluePoolManager.CluePoolPublicRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author luojie
 * @date 2021/5/13 16:40
 */
@Service
public class CluePoolPrivateRedisServiceImpl implements CluePoolPrivateRedisService {

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 根据id获取key
     * @param id
     * @return
     */
    private String getKey(String id){
        String key = RedisPrefix.CLUE_POOL_PRIVATE + id;
        return key;
    }

    @Override
    public CluePoolPrivate getCluePoolPrivateById(String cluePoolPrivateId) {
        String key = getKey(cluePoolPrivateId);
        CluePoolPrivate cluePoolPrivate =  ValueRMapper.getRedisObject(redisTemplate,key, CluePoolPrivate.class);
        return cluePoolPrivate;
    }

    @Override
    public Boolean setCluePoolPrivateById(CluePoolPrivate cluePoolPrivate) {
        String id = cluePoolPrivate.getCluePoolPrivateId();
        String key = getKey(id);
        return ValueRMapper.setRedisObject(redisTemplate,key,cluePoolPrivate);
    }

    @Override
    public Boolean deleteCluePoolPrivateById(String cluePoolPrivateId) {
        String key = getKey(cluePoolPrivateId);
        return ValueRMapper.delRedis(redisTemplate,key);
    }
}
